Skip to main content

Using the Command-Line Interface

You can start CODESYS.exe from the command line with the following options and arguments.

Syntax:

<installation folder>CODESYS.exe --<Option>

Note

If you have used the CODESYS Installer to install multiple CODESYS instances on your computer, then you need to use the --additionalfolder option to specify the instance to be launched.

Tip

Paths or option parameters must be written inside straight quotation marks when they contain spaces, dashes, or slash marks.

Option: --additionalfolder

Applies only to installations made with the CODESYS Installer:

If you have installed multiple instances of a CODESYS version and want to start one of the instances from the command line, then the following applies: In addition to the profile, you also need to specify the absolute path of the AddionalFolder/<instance name> with the --additionalfolder option.

Background: The CODESYS Installer creates an AdditionalFolders subfolder in the installation directory in the CODESYS folder. In this folder, there is a separate subfolder for each CODESYS instance with the individual files for profile, PlugIns, and PackageDB. For the first installed instance, the subfolder is named Default. Additional instances are given the installation name assigned during installation.

You can see the absolute path to be specified for --additionalfolder in CODESYS Installer when you click the Change button in the tile of the relevant instance. It is registered as the Location.

Syntax:

--additionalfolder=<AdditionalFolders\<instance installation name>>
Example 44. Example

Two instances of CODESYS 3.5.18.20 have been installed on your computer with the CODESYS Installer: one for service technicians, one for developers. You want to run the Service instance via a StartServiceScript.py script from command line. To do this, specify the --additionalfolder option after the --profile option on the command line as follows:

"C:\Program Files (x86)\CODESYS3.5.18.20\CODESYS\Common\CODESYS.exe" --profile="CODESYS V3.5 SP18 --additionalfolder="C:\Program Files\CODESYS 3.5.18.20\CODESYS\AdditionalFolders\Service"  --runscript="D:\Dokumente\Scripting\StartServiceScript.py"--scriptargs:'username password 3.14 "path=\"C:\temp\\\""'–noUI


Option: --culture (language of the user interface)

CODESYS is started in the specified language.

Syntax:

--culture=<Culture>

<culture>: Typical language codes are as follows: de, en, fr, it, es, zh-CHS.

Example 45. Example

Starting CODESYS with the user interface in English:

CODESYS.exe --culture=en


Option: --profile (CODESYS profile)

CODESYS is started directly with the specified profile. When you start CODESYS without this option, the Select Profile opens.

Syntax:

--profile="<profile name>"

<profile name>: You need to specify the profile name exactly as it is displayed in the Help → About splash screen of the development system or in the start menu on your computer.

Example 46. Example
CODESYS.exe --culture=de --profile="CODESYS V3.6"


Option: --compare (start project comparison)

After CODESYS is started, the comparison of two CODESYS projects is begun immediately. After the option, first specify the "current project" and then the "reference project" as arguments. CODESYS starts and opens the Project Comparison – Differences view.

Syntax:

--compare="<path of project file>" "<path of reference project file>"
Example 47. Example
CODESYS.exe --compare  "D:\proj\project1.project"  "D:\proj\project2.project"


Option: --project (open CODESYSproject)

CODESYS is started and the specified project is opened.

Syntax:

--project="<path of project file>"

<path of project file>: File path of project

Example 48. Example

Open the test project:

CODESYS.exe --culture=de --project="D:\projects\test.project"


Option: --projectarchive (open CODESYS project archive)

CODESYS is started, the specified project archive is extracted, and the project is opened.

Syntax:

--projectarchive="<path of projectarchive file>"

<path of project archive file>: File path of project archive

Example 49. Example

Extract the test.projectarchive and open the project in the development system:

CODESYS.exe --projectarchive="D:\projects\test.projectarchive"


Option: --runscript (run script)

The specified script file is run by CODESYS.

Table 8. Command Line Options for --runscript

--runscript="<script file>.py"

CODESYS runs the <script file>.py script file at startup.

You need to provide the complete path of the script file.

--scriptargs:'<arg1> <arg2> ... <argn>'

Use this option with the --runscript option. They trigger the passing of the <arg1> … <argn> arguments to the script. The arguments are passed to the Python variable sys.argv.

--noUI

Use this option with the --runscript option.

The CODESYS user interface is not opened. CODESYS outputs all errors, warnings, compiler reports, and command-line messages generated from the script. The script messages (1: Severity Text) can be separated from other messages (2: Severity FatalError, Error, Warning, Information) with the > operator.

--enablescripttracing

Use this option with the --runscript option. As a result, each command of the script file is shown in the output.

--textPrompts

Use this option with the --noUI option. As a result, message service methods and default dialogs are output in the command line for user input.

If you do not specify --textPrompts, then all message service prompts are confirmed automatically with default values.

scriptdebugger {="<debugger>"}

Use this option with the --runscript option. It sets IronPython in debug mode so that external debuggers can be used to debug Python scripts. The following values are defined for <debugger> (not case sensitive):

  • auto: Automatically detects if a debugger is included in every script for the current process. At this time, only .NET-based debuggers can be detected automatically. A detected debugger overwrites the --enablescripttracing flag.

  • .NET: Activates debugging for .NET-based debuggers, such as "Python Tools for Visual Studio" (PTVS) and SharpDevelop. With this option, a debugger can also be included in running scripts, as opposed to "auto".

    Note: This is currently the default value when --scriptdebugger is used without providing a value.

  • disabled: Deactivates debugging and automatic detection.

  • script: Switches the IronPython script engine to debug mode for activating the debugging for set-trace debuggers. The script itself must connect to and disconnect from the debugger.

  • tracing: Activates the simple integrated "script tracing" mode and deactivates the automatic detection (same as the option --scripttracing).

  • $absolute_path.py$: Absolute path to a Python script that initiates the connection to a Python-based debugger. The IronPython script engine is switched to debug mode for allowing the debugging for set-trace debuggers. This script is run one time during the initialization and should define the following non-parameterized functions:

    scriptdebuggersetup is run immediately before running the user script to establish the connection to the debugger.

    scriptdebuggershutdown is called immediately after running the user script or when the script engine is downloaded and should close the connection to the debugger.



Example 50. Examples of using transfer parameters in script files with 'sys.argv'
start /b /wait CODESYS.exe
--runscript="D:\Script\ArgvAnd__main__Test.py"
--scriptargs:'username password 3.14 "path=\"C:\temp\\"'

Script file: ArgvAnd__main__Test.py

from __future__ import print_function
import sys
print("sys.argv: ", len(sys.argv), " elements:")

for arg in sys.argv:
    print(" - ", arg)
print()
print("__name__: ", __name__)

Output result: stdout:

sys.argv: 6 elements:
- D:\TestScripts\ArgvAnd__main__Test.py
- username
- password
- 3.14
- path= "C:temp"
__name__: __main__

For more information about the __name__ global variable, see the Python documentation.



Example 51. Examples of the message output
start /b /wait CODESYS.exe --runscript="D:\Script\AmpelTest.py" --noUI 1>ScriptMessages.txt

CODESYS passes all messages which are generated by the script to the ScriptMessages.txt file. Other messages are printed to the command line.

start /b /wait CODESYS.exe --runscript="D:\Script\AmpelTest.py" --noUI 2>NUL

CODESYS suppresses all messages, except for script messages. The script messages are printed to the command line.



Example 52. Example of using the –scriptdebugger option

The following initdebug.py script was tested successfully with pydevd-based debuggers, such as PyDev / LiClipse and PyCharm. To use this script, start CODESYS with the following command line:

--profile="Fanta Development Build" --scriptdebugger="D:\test\charmdebug\initdebug.py"

File: initdebug.py:

from _future_ import print_function
from _future_ import unicode_literals
import sys
sys.path.append(r"D:\test\Env2\Lib\site-packages\pycharm-debug.egg")
import pydevd
def scriptdebuggersetup():
pydevd.settrace('localhost', port=51234, stdoutToServer=True, stderrToServer=True)
def scriptdebuggershutdown():
pydevd.stoptrace()


For more information see: Using Scripts and http://docs.python.org/tutorial/modules.html

Option: --ignorewhitespace (ignore whitespace in project comparison)

If you add this option after the option --compare <project1> <project2>, then whitespace is ignored in the project comparison. Note that semantically relevant spaces, for example in STRING literals, are still taken into account.

Syntax

--compare="<path of project file>" "<path of reference project file>" --ignorewhitespace="true"|"false"
Example 53. Example
CODESYS.exe --compare "D:\proj\project1.project" "D:\proj\project2.project" --ignorewhitespace="true"


Option: --ignorecomments (ignore comments in project comparison)

If you add this option after the option --compare <project1> <project2>, then comments are ignored in the project comparison.

Syntax:

--compare="<path of project file>" "<path of reference project file>" --ignorecomments="true"|"false"
Example 54. Example
CODESYS.exe --compare "D:\proj\project1.project" "D:\proj\project2.project" --ignorecomments="true"


Option: --ignoreproperties (ignore object properties in project comparison)

If you add this option after the option --compare <project1> <project2>, then object properties (permissions, compile settings, directories, bitmaps, etc.) are ignored in the project comparison.

Syntax:

--compare="<path of project file>" "<path of reference project file>" --ignoreproperties="true"|"false"
Example 55. Example
CODESYS.exe --compare "D:\proj\project1.project" "D:\proj\project2.project" --ignoreproperties="true"


Option: --skipunlicensedplugins (do not load components without a license)

CODESYS is started. In this case, the query as to whether unlicensed components should still be loaded is skipped. If so, then CODESYS does not silently load these components.

Example 56. Example
CODESYS.exe –skipunlicensedplugins


Option: --signaturethumbprint (thumbprint of the certificate which is used for signing compiled libraries)

If you add this option after the option --project="<path of project file>", then the project is opened and the thumbprint of the certificate for signing compiled libraries is passed.

Syntax:

--signaturethumbprint="<thumbprint of digital signature>"
Example 57. Example
CODESYS.exe --project="D:\projects\test.project" signaturethumbprint="3E96C9B61010CBDC3186021A1CAA64946DDCAAF3"


Option: --enforcesignedcompiledlibraries (enforce signing of compiled libraries)

If you add this option after the option --project="<path of project file>", then the Enforce signing of compiled libraries option is enabled in the project in the Security Screen on the User tab.

Important

When the Security Screen is opened and closed again, the current settings are applied in the user options, even when no active changes have been made.

Syntax:

--enforcesignedcompiledlibraries
Example 58. Example
CODESYS.exe --project="D:\projects\test.library" --enforcesignedcompiledlibraries


Option: --timestampingserverurl (set the time stamp server address)

If you add this option after the option --project="<path of project file>", then the Internet address of the RFC-3161 time stamp server (Timestamping server) is set in the project in the Security Screen on the User tab.

Important

When the Security Screen is opened and closed again, the current settings are applied in the user options, even when no active changes have been made.

Syntax:

--timestampingserverurl="<URL of RFC-3161 timestamping server>"
Example 59. Example
CODESYS.exe --timestampingserverurl="http://timestamp.comodoca.com/rfc3161"


Option: --enableEventLog

CODESYS is started and all command executions are recorded in the Windows event log. The records are located in the Windows Event Viewer under Applications and Services Logs → AP.

When using this option for the first time, CODESYS has to be started with administrator permissions.

Syntax:

--enableEventLog="CommandManager"

Option: --ForceDisconnectAfterInactivity

For this CODESYS session, the time of inactivity after which the connection to the controller is automatically terminated is set to the specified time (in seconds). The value specified in this option overrides the value set in the CODESYS options in the Online category for this CODESYS session.

If the value is set to 0, then the connection to the controller will not be automatically terminated after a specific period of inactivity. For this CODESYS session, this disables the disconnect option in the CODESYS options.

Syntax:

--ForceDisconnectAfterInactivity="<value in seconds>"
<value in seconds> : [10, 10800] | 0
Example 60. Example

After 300 seconds of inactivity, the connection to the controller is automatically terminated.

--ForceDisconnectAfterInactivity="300"